﻿@using hc.epm.DataModel.Business;
@using System.Collections.Generic;
@using hc.epm.Common;
@using hc.Plat.Common.Extend;
@using hc.epm.DataModel.Basic
@model List<Base_Company>
@{
    ViewBag.Title = "供应商管理列表";
}

<link href="~/Resource/css/ProjectManagement.css" rel="stylesheet" />
<style>
    .col-lg-3 {
        width: 29%;
        margin-top: 6px;
        padding-right: 0;
        font-weight: 100;
    }

    .form-sub {
        display: flex;
        justify-content: space-between;
        margin-bottom: 25px;
    }

        .form-sub > button, .wrap-but > button {
            width: 150px;
            height: 35px;
            border: none;
            background-color: #6a6969;
            color: #fff;
        }
</style>

<div class="contentData">
    <div class="form-query">
        <form method="get">

            <div class="module-div">
                <h4>查询条件</h4>
                <div class="row list-box" style="margin:10px -15px">
                    <div class="col-lg-4 col-sm-4">
                        <div class="form-group">
                            <label class="control-label col-lg-3 col-sm-3">供应商名称：</label>
                            <div class="col-lg-8 col-sm-8 control-label-div">
                                <input class="form-control" type="text" name="name" value="@ViewBag.name" placeholder="请输入供应商名称">
                               
                            </div>
                        </div>
                    </div>

                    <div class="col-lg-4 col-sm-4">
                        <div class="form-group">
                            <label class="control-label col-lg-3 col-sm-3">供应商电话：</label>
                            <div class="col-lg-8 col-sm-8 control-label-div">
                                <input class="form-control" type="text" name="phone" value="@ViewBag.phone" placeholder="请输入供应商电话">
                            </div>
                        </div>
                    </div>
                    <div class="col-lg-4 col-sm-4" style="margin-top:10px;">
                        <div class="form-group">
                            <label class="control-label col-lg-3 col-sm-3">是否黑名单：</label>
                            <div class="col-lg-8 col-sm-8 control-label-div">
                                <select class="form-control" name="isblack" value="@ViewBag.isblack">
                                    <option value="">请选择</option>
                                    <option value="1">是</option>
                                    <option value="0">否</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="col-lg-4 col-sm-4" style="margin-top:10px;">
                        <div class="form-group">
                            <label class="control-label col-lg-3 col-sm-3">供应商类型：</label>
                            <div class="col-lg-8 col-sm-8 control-label-div">
                                @Html.DropDownList("companyType", ViewBag.CompanyType as SelectList, null, new { @class = "form-control" })
                            </div>
                        </div>
                    </div>
                    <div class="col-lg-4 col-sm-4" style="margin-top:10px;">
                        <div class="form-group">
                            <label class="control-label col-lg-3 col-sm-3">供应商级别：</label>
                            <div class="col-lg-8 col-sm-8 control-label-div">
                                @Html.DropDownList("companyRank", ViewBag.CompanyRank as SelectList, null, new { @class = "form-control" })
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="form-sub">
                <div class="wrap-but">
                    <button type="button" id="add" class="checkright" data-module="SupplierManage" data-right="Add">新增</button>
                    <button type="button" id="del"  class="checkright" data-module="SupplierManage" data-right="Delete">删除</button>
                </div>

                <button type="submit" id="btnsel" class="checkright" data-module="SupplierManage" data-right="Browse">查 询</button>
            </div>
        </form>
    </div>

    <div class="list-tab">
        <table class="datalist" style="word-break:break-all;word-wrap:break-word">
            <thead>
                <tr>
                    <th width="50">
                        <input type="checkbox" id="allcheck" />
                    </th>
                    <th width="200">供应商名称</th>
                    <th width="100">供应商电话</th>
                    <th width="100">供应商类型</th>
                    <th width="100">供应商级别</th>
                    <th width="100">供应商地址</th>
                    <th width="100">是否黑名单</th>
                    <th width="100">操作</th>
                </tr>
            </thead>
            <tbody id="tbody">
                @{
                    int index = (ViewBag.pageIndex - (ViewBag.pageIndex - 1)) * ((ViewBag.pageIndex - 1) * 10);
                }
                @if (Model != null && Model.Count > 0)
                {
                    foreach (var item in Model)
                    {
                        index++;
                        <tr>
                            <td style="display:none">
                                <input type="hidden" class="inputId" data-id="@item.Id" data-sid="@item.SId" />
                            </td>
                            <td width="50">
                                <input type="checkbox" value="@item.SId" />
                            </td>
                            <td>@item.Name</td>
                            <td>@item.Phone</td>
                            <td>@item.CompanyTypeName</td>
                            <td>@item.CompanyRankName</td>
                            <td>@item.AddressName</td>
                            @if (item.IsBlacklist == true)
                            {
                                <td>是</td>
                            }
                            else {
                                <td>否</td>
                            }



                            <td>
                                <a class="edit checkright" style="cursor:pointer;color:#0099FF;padding: 6px;" data-module="SupplierManage" data-right="Modify">编辑</a>

                                <a class="Detail checkright" style="cursor:pointer;color:#0099FF;padding: 6px;" data-module="SupplierManage" data-right="Info">查看</a>

                                <a class="userManage " style="cursor:pointer;color:#0099FF;padding: 6px;" >人员管理</a>
                            </td>
                        </tr>
                    }
                }
                else {
                    <tr>
                        <td colspan="8" class="table-center">
                            暂无数据
                        </td>
                    </tr>
                }

            </tbody>
        </table>
    </div>
    <div id="page" style="text-align:right; margin-right:5px;"></div>
</div>

<script>
    //全选反选
    $("#allcheck").click(function () {
        var isChecked = $("#allcheck").prop("checked");
        $("#tbody input[type='checkbox']").prop("checked", isChecked);
    });

    // 单独选项控制全选
    $("#tbody input[type='checkbox']").click(function () {
        var allLength = $("#tbody input[type='checkbox']").length;
        var checkedLength = $("#tbody input[type='checkbox']:checked").length;
        if (allLength == checkedLength) {
            $("#allcheck").prop("checked", true);
        } else {
            $("#allcheck").prop("checked", false);
        }
    });

    layui.use(['layer', 'element', 'laypage'], function () {
        var layer = layui.layer, form = layui.form, element = layui.element, $ = layui.jquery, laypage = layui.laypage;
        //分页
        laypage.render({
            elem: 'page',
            count: '@ViewBag.Total',
            curr: '@ViewBag.pageIndex',
            theme: '#6a6969',
            layout: ['prev', 'page', 'next', 'skip', 'count'],
            jump: function (obj, first) {
                if (!first) {
                    //得到了当前页，用于向服务端请求对应数据
                    var curr = obj.curr;
                    var search = $("form").serialize();
                    window.location.href = "/Company/SupplierIndex?pageIndex=" + curr + "&" + search;
                }
            }
        });

        //删除
        $("#del").click(function () {
            var hfId = "";
            var idData = [];
            var chkItems = $('#tbody input[type="checkbox"]:checked');
            chkItems.each(function (index, item) {
                hfId += $(this).val() + ',';
                idData.push($(this).val());
            });

            if (idData.length == 0) {
                layer.msg('请先选择要删除的数据！', { time: 1000, icon: 2 });
                return;
            };

            if (hfId.length != 0) {
                parent.layer.confirm('确认要删除所选择的项？', { icon: 3 }, function () {
                    $.post("/Company/Delete", { ids: hfId }, function (data) {
                        if (data.Flag) {
                            parent.layer.msg("操作成功", { time: 2000, icon: 1 });
                            location.reload();
                        } else {
                            layer.alert(data.Message, { time: 1000, icon: 2 });
                        }
                    }, "json");
                });
            }
        });
    });


    //新增
    $("#add").on("click", function () {
        window.location.href = "/Company/SupplierAdd";
    });

    //编辑
    $(".edit").on("click", function () {
        var id = $(this).parents("tr").find(".inputId").data("sid");
        window.location.href = "/Company/SupplierEdit?id=" + id;
    });

    //查看
    $(".Detail").on("click", function () {
        var id = $(this).parents("tr").find(".inputId").data("sid");
        window.location.href = "/Company/SupplierDetail?id=" + id;
    });
 
    //人员管理
    $(".userManage").on("click", function () {
        var id = $(this).parents("tr").find(".inputId").data("sid");
        window.location.href = "/User/UserList?CompanyId=" + id;
    });
</script>